package com.douguo.recipe.network;

import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import com.douguo.recipe.object.Caixi;
import com.douguo.recipe.object.HomeCategory;
import com.douguo.recipe.object.Kouwei;
import com.douguo.recipe.object.Sort;
import com.douguo.recipe.object.Tese;

import android.graphics.Bitmap;
import android.os.Message;
import android.util.Log;
import android.util.Xml;

public class LoadCachePhoto {
	private static final String TAG = "LoadCachePhoto";
	
	public static Bitmap getPhoto(String url){
		Bitmap bm;
		//先读sdcard
		bm = Util.readCachePhoto(url);
		
		//失败后读取网络
		if(bm == null) {
			Log.d(TAG, "no photo");
			DouguoConnection mConn = new DouguoConnection(url, null,
					mParseListener, DouguoConnection.GET_METHOD);
			SoftReference<Bitmap> refBitmap = (SoftReference<Bitmap>) mConn
					.Connect();
			if(refBitmap != null) {
				bm = refBitmap.get();
				if(bm != null) {//保存到sdcard
					Util.saveBitmapToSDCardFromUrl(bm, url, true);
				}
			}
		}
		return bm;
	}
	
	private static OnParseListener mParseListener = new OnParseListener() {

		public Object onParsing(InputStream is) {
			
			return Util.inputStreamToRefBitmap(is);// SoftReference
		}

	};

}
